package jrobutt;

import java.awt.Image;
import java.awt.Graphics2D;

public class GameSprite
{
    public final Image image;
    
    public final int width;
    public final int height;
    
    public final int xanchor;
    public final int yanchor;
    
    public GameSprite (Image image, int xanchor, int yanchor)
    {
        this.image = image;
        
        this.width = image.getWidth(null);
        this.height = image.getHeight(null);
        
        this.xanchor = xanchor;
        this.yanchor = yanchor;
    }
    public GameSprite (Image image, float xoffsetratio, float yoffsetratio)
    {
        this.image = image;
        
        this.width = image.getWidth(null);
        this.height = image.getHeight(null);
        
        this.xanchor = (int)((float)width * xoffsetratio);
        this.yanchor = (int)((float)height * yoffsetratio);
    }
    public GameSprite (Image image)
    {
        this(image, 0, 0);
    }
    
    public void renderAt (Graphics2D g, float x, float y)
    {
        int ix = (int)(x - xanchor);
        int iy = (int)(y - yanchor);
        g.drawImage(image, ix, iy, null);
    }
}
